package com.zeyi.chat.utils;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zeyi
 */
public class EmailUtil {
    private static final String HOST_NAME = "smtp.qq.com";
    private static final String CHARSET = "utf-8";
    private static final String FROM = "960114038@qq.com";
    private static final String FROM_NAME = "泽毅";
    private static final String USERNAME  = "960114038@qq.com";
    private static final String PASSWORD  = "vnwwdsayxxxxx";
    private static Map<String, String> checkCodeMap = new HashMap<>();

    public static boolean sendEmail(String receiver, String content) {
        HtmlEmail email=new HtmlEmail();
        email.setHostName(HOST_NAME);
        email.setCharset(CHARSET);
        try {
            email.addTo(receiver);
            email.setFrom(FROM, FROM_NAME);
            email.setAuthentication(USERNAME, PASSWORD);
            email.setSubject("验证码");//设置发送主题
            email.setMsg(content);//设置发送内容
            email.send();
            return true;
        } catch (EmailException e) {
            return false;
        }
    }
}
